package com.zuowei.ycy.user.ui.mine;

import android.view.View;
import android.widget.EditText;

import com.and.yzy.frame.util.MatchStingUtil;
import com.and.yzy.frame.util.RetrofitUtils;
import com.zuowei.ycy.R;
import com.zuowei.ycy.user.http.Article;
import com.zuowei.ycy.ui.BaseToolbarAty;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

/**
 * 意见反馈
 */
public class MineYiJianAty extends BaseToolbarAty {
    @Bind(R.id.et_content)
    EditText mEtContent;
    @Bind(R.id.et_phone)
    EditText mEtPhone;

    @Override
    public int getLayoutId() {
        return R.layout.mine_yijian_layout;
    }

    @Override
    public void initData() {
        mToolbar.setTitle("意见反馈");
    }

    @Override
    public void requestData() {

    }

    @OnClick(R.id.tv_commit)
    @Override
    public void btnClick(View view) {
        super.btnClick(view);
        switch (view.getId()) {
            case R.id.tv_commit:

                if (mEtContent.getText().toString().trim().equals("")) {
                    showToast("请填写产品意见");

                    mEtContent.requestFocus();
                    return;
                }
                if (mEtPhone.getText().toString().trim().equals("")) {
                    showToast("手机号不能为空");

                    mEtPhone.requestFocus();
                    return;
                }
                if (!MatchStingUtil.isMobile(mEtPhone.getText().toString().trim())) {
                    showToast("手机号格式不对");
                    mEtPhone.requestFocus();
                    return;
                }


                showLoadingDialog("正在提交");

                doHttp(RetrofitUtils.createApi(Article.class).addFeedback(mEtContent.getText().toString().trim(), mEtPhone.getText().toString().trim()), 1);


                break;

        }
    }


    @Override
    public void onSuccess(String result, Call<ResponseBody> call, Response<ResponseBody> response, int what) {

        showToast("提交意见成功");
        finish();

        super.onSuccess(result, call, response, what);
    }
}
